//
//  NewsVC.m
//  CYLTabBarControllerTest
//
//  Created by intest_zyy on 2019/1/17.
//  Copyright © 2019 coder_zyy. All rights reserved.
//

#import "NewsVC.h"
#import "UINavigationBar+handle.h"

#import "UIColor+Addition.h"
#import "ZYYbackView.h"

#import "NewsCell.h"
#import "UITableViewCell+FSAutoCountHeight.h"

#define ZYYWeakSelf __weak typeof(self) weakSelf = self;

static NSString *NewsCellID = @"NewsCellID";

@interface NewsVC ()

@end

@implementation NewsVC

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        self.title = @"新闻";
        
        self.view.backgroundColor = [UIColor colorWithRed:44 green:44 blue:44];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.tabBarItem setBadgeValue:@"3"];
    
    [self setNavUI];
    [self setTabViewUI];
    
}
- (void)setNavUI
{
    ZYYbackView *NoticeView = [ZYYbackView backViewWithImageName:@"notice" highlightImagename:@"notice" titleImage:nil target:self action:@selector(clickNoticeBtn)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:NoticeView];
}
- (void)clickNoticeBtn
{
    
}

- (void)setTabViewUI
{
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"NewsCell" bundle:nil] forCellReuseIdentifier:NewsCellID];
}

#pragma mark - Methods

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath {
    [[cell textLabel] setText:[NSString stringWithFormat:@"%@ Controller Cell %ld", self.title, (long)indexPath.row]];
}

#pragma mark - Table view

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYYWeakSelf;
    NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:NewsCellID];
    if (!cell) {
        cell = [[NewsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NewsCellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.clickTagsBtnBlock = ^(NewsCell * cell) {
        [weakSelf click_TagsBtn:cell];
    };
    cell.clickReviewBtnBlock = ^(NewsCell * cell) {
        [weakSelf click_ReviewBtn:cell];
    };
    
//    [self configureCell:newsCell forIndexPath:indexPath];
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    [self.navigationController.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", indexPath.row+1]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 自动计算cell高度
    CGFloat height = [NewsCell FSCellHeightForTableView:tableView indexPath:indexPath cellContentViewWidth:0 bottomOffset:0];
    return (height + 0);
}

- (void)click_TagsBtn:(NewsCell *)cell
{
    NSLog(@"点击了点赞按钮");
}
- (void)click_ReviewBtn:(NewsCell *)cell
{
    NSLog(@"点击了评论按钮");
}

@end
